package com.cpi.cornpp.productpurchase.converter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.cpi.cornpp.productpurchase.dto.ProductPurchaseDTO;
import com.cpi.cornpp.productpurchase.view.ProductPurchaseView;

public class ProductPurchaseConverter {


	public ProductPurchaseDTO convert(ProductPurchaseView view){
		ProductPurchaseDTO dto = new ProductPurchaseDTO();
		dto.setProductId(view.getProductId());
		dto.setCornFutureDistributionId(view.getCornFutureDistributionId());
		dto.setDescription(view.getDescription());		
		dto.setQuantity(view.getQuantity());
		
		return dto; 
	}
	
	public ProductPurchaseView convert(ProductPurchaseDTO dto){
		ProductPurchaseView view = new ProductPurchaseView();
		view.setProductId(dto.getProductId());
		view.setCornFutureDistributionId(dto.getCornFutureDistributionId());
		view.setDescription(dto.getDescription());		
		view.setQuantity(dto.getQuantity());
		return view; 
	}

	public List convertDtos(List listProductPurchases){
		Iterator iterator = null;
		ArrayList arrayResult = null;
		ProductPurchaseDTO dto = null;				
		arrayResult =  new ArrayList(0);
		//Obtengo la cantidad de Iteraciones que estare haciendo para recorrer el List ProductPurchase
		iterator = listProductPurchases.iterator();		
		while (iterator.hasNext()){
			dto = (ProductPurchaseDTO)iterator.next();
			arrayResult.add(convert(dto));
		}
		return arrayResult;
	}
	

	public final List convertViews(Collection productPurchaseDTOs){
		List productPurchases = null;
		
		productPurchases = new ArrayList(0);
		
		if (!CollectionUtils.isEmpty(productPurchaseDTOs)){
			Iterator iterator = productPurchaseDTOs.iterator();
			ProductPurchaseView view = null;
			while(iterator.hasNext()){
				view = (ProductPurchaseView)iterator.next();
				productPurchases.add(convert(view));
			}
		}
		
		return productPurchases;
	}

	
	

}
